import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from supervised_vgg16 import super_vgg16
from vgg16 import data_preprocessing,prepare_data

#加载方法1：
image = tf.placeholder(tf.float32,shape=(None,32,32,3),name='input_x')
y_ = tf.placeholder(tf.float32,[None,10],name='input_y')
keep_prob = tf.placeholder(tf.float32,name='prob')
loss,logits = super_vgg16(image,y_,keep_prob,phase=False)
# logits = vgg16(image,keep_prob,train_flag)
saver = tf.train.Saver()

pred_val = tf.nn.softmax(logits)

with tf.Session() as sess:
    saver.restore(sess,tf.train.latest_checkpoint('./supervised_vgg16_model'))
    print("finish loading model!")

    train_x, train_y, test_x, test_y = prepare_data()
    train_x, test_x = data_preprocessing(train_x, test_x)

    per_dataset = np.load("./deepfoolattack_vgg16_all.npy")
    test_image = per_dataset[6].reshape(1,32,32,3)
    test_label = test_y[6]
    pred_label = np.argmax(sess.run(logits, feed_dict={image: test_image, keep_prob: 1.0}))
    print("预测标签为：", pred_label)
    print("真实标签为：", np.argmax(test_label))

    pred = sess.run(pred_val,feed_dict={image:test_image,keep_prob:1.0}).squeeze()
    pred_l = np.argsort(pred)
    acc = pred[pred_l[9]]*100
    print("预测置信度为：",str(acc))

